<template>
  <div>
    <div class="header">
      <div class="header_title">当前城市</div>
      <div class="search">
        <div><i class="iconfont icon-sousuoxiao"></i></div>
        <div><input type="text" placeholder="输入城市名或拼音" /></div>
      </div>
    </div>
    <div class="hot_city">
      <div class="GPS_city">
        <p>GPS定位你所在城市</p>
        <button>定位失败</button>
      </div>
      <div class="hot">
        <p>热门城市</p>
        <div>
          <button v-for="item of hotcities" :key="item.id" @click="handleCity(item.name)">
            {{ item.name }}
          </button>
        </div>
      </div>
    </div>
    <div class="citys">
      <van-index-bar>
        <div v-for="(item,index) of cities" :key="index">
        <van-index-anchor :index=index />
        <div 
            v-for="data of item" 
            :key="data.id"
            @click="handleCity(data.name)" 
            class="city_name">
        <van-cell title="" />{{data.name}}     
        </div>   
        </div>  
      </van-index-bar>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      hotcities: [],
      cities: [],
    };
  },
  mounted() {
    this.$http.get("http://47.108.197.28:8000/city").then((res) => {
      // console.log(res.data.data);
      this.hotcities = res.data.data.hotCities;
      this.cities = res.data.data.cities;
      // console.log(this.hotcities)
      // console.log(this.cities)
    });
  },
  methods: {
      handleCity(val){
        // console.log(city);
        this.$store.dispatch("city",val)
        this.$router.back()
      }
  },
};
</script>

<style scoped>
.header {
  /* position: fixed; */
  height: 50px;
}

.icon-zuojiantou {
  font-size: 40px;
  position: absolute;
  left: 10px;
  top: 10px;
}
.header_title {
  text-align: center;
  margin: auto auto;
  font-size: 30px;
  padding-top: 15px;
  padding-bottom: 15px;
  background-color: #fff;
}
.search {
  display: flex;
  margin: 20px 40px;
  background-color: #fff;
  padding: 15px 20px;
}
.search input {
  border: none;
  outline: none;
}
.icon-sousuoxiao {
  font-size: 30px;
  margin: auto 10px;
}
.hot_city {
  background-color: #fff;
  padding: 15px 25px;
}
.hot_city p {
  margin: 20px auto;
  color: rgb(92, 89, 89);
}
.GPS_city {
  margin-top: 100px;
}
.GPS_city button {
  margin-left: 20px;
  padding: 15px 25px;
}
.GPS_city button,
.hot button {
  border: none;
  font-size: 25px;
  color: rgb(37, 36, 36);
}
.hot > div {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
.hot button {
  padding: 25px 35px;
}
.city_name{
    margin: 20px;
    font-size: 15px;

}
</style>